package graph;
import java.util.ArrayList;
import java.util.List;

public class Vertex {
	private static int CURRENT_NUMBER = 1;
	/**
	 * @uml.property  name="name"
	 */
	private int name;
	/**
	 * @uml.property  name="neighbours"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="graph.Vertex"
	 */
	private List<Vertex> neighbours;

	public Vertex() {
		this.name = Vertex.CURRENT_NUMBER++;
		this.neighbours = new ArrayList<Vertex>();
	}

	public boolean contains(Vertex v) {
		if (this.name == v.name)
			return true;

		for (Vertex s : neighbours) {
			if (s.name == v.name) {
				return true;
			}
		}
		return false;
	}
		
	public void addNeighbours(Vertex v) {
		if (!this.contains(v))
			this.neighbours.add(v);
		if (!v.contains(this))
			v.neighbours.add(this);
	}

	public void addNeighbours(List<Vertex> neighbours) {
		for (Vertex v : neighbours) {
			addNeighbours(v);
		}
	}

	public void removeNeighbour(Vertex v) {
		this.neighbours.remove(v);
	}

	public int numberNeighbour(){
		return neighbours.size();
	}
	
	/**
	 * @return
	 * @uml.property  name="name"
	 */
	public int getName(){
		return this.name;
	}
	
	public List<Vertex> getNeighbours(){
		return this.neighbours;
	}
	
	public int getDegree() {
		return (neighbours != null ? neighbours.size() : 0);
	}

	public String printNeighbours() {
		return this.toString() + this.neighbours.toString();
	}

	public String toString() {
		return String.valueOf(this.name);
	}
	public String toStringNeighbour(){
		return String.valueOf(this.name) + "(" + this.numberNeighbour() + ")";
	}
}
